<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/jsp/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>角色按钮权限配置窗体</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <style>


    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-6">
            <div class="ibox float-e-margins">

                <div class="ibox-content">
                    <form onsubmit="return  false" class="form-horizontal m-t" id="roleForm">

                        <div class="form-group">
                            <table id="roleButtonTable"></table>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3" style="padding-left: 0px;">
                                <button class="btn btn-primary" onclick="doSubmit();">提交</button>
                                <button id="btn_close" class="btn btn-primary" type="button">关闭</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/bootstrap-table.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/locale/bootstrap-table-zh-CN.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/export/bootstrap-table-export.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/editable/bootstrap-table-editable.js"></script>
<script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/validate/jquery.validate.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/chosen/chosen.jquery.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/layer2.4/layer.js"></script>



<script>
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    //关闭按钮事件
    $('#btn_close').click(function(){
        parent.layer.close(index);
    });



    //初始化表格对象
    $('#roleButtonTable').bootstrapTable({
        url: "${pageContext.request.contextPath}/role/showRoleButtonGrid.ac?prole.id="+"${role.id}",
        columns: [{
            field: 'menu_name',
            title: '',
            formatter:function(value,row,index){
                return [
                    '<span style="margin-left: 15px !important; ">'+value+'</span>',
                    '<input type="hidden" name="prole.roleButtonList['+index+'].id" value="'+row.id+'">',
                    '<input type="hidden" name="prole.roleButtonList['+index+'].nameSpace" value="'+row.nameSpace+'">',
                    '<input type="hidden" name="prole.roleButtonList['+index+'].href" value="'+row.href+'">'
                ].join('');
            }
        }, {
            field: 'permission',
            title:
                    '<input id="addCtrl" type="checkbox" style="margin-left: 18px !important;" onchange="selectAllCheck(\'add\')"><span style="font-weight: normal !important;">增</span>'+
                    '<input id="delCtrl" type="checkbox" style="margin-left: 18px !important;" onchange="selectAllCheck(\'del\')"><span style="font-weight: normal !important;">删</span>'+
                    '<input id="updCtrl" type="checkbox" style="margin-left: 18px !important;" onchange="selectAllCheck(\'update\')"><span style="font-weight: normal !important;">改</span>'+
                    '<input id="queCtrl" type="checkbox" style="margin-left: 18px !important;" onchange="selectAllCheck(\'query\')"><span style="font-weight: normal !important;">查</span>',
            formatter:function(value,row,index){
                var add='<input type="checkbox" class="add_all" style="margin-left: 18px !important;" name="prole.roleButtonList['+index+'].add">增'
                var del='<input type="checkbox" class="del_all" style="margin-left: 18px !important;" name="prole.roleButtonList['+index+'].del">删'
                var update='<input type="checkbox" class="update_all" style="margin-left: 18px !important;" name="prole.roleButtonList['+index+'].update">改'
                var query='<input type="checkbox" class="query_all" style="margin-left: 18px !important;" name="prole.roleButtonList['+index+'].query">查'

                if (row.add == 1) {
                    add='<input type="checkbox" class="add_all" style="margin-left: 18px !important;" checked  name="prole.roleButtonList['+index+'].add">增'
                }
                if (row.del == 1) {
                    del='<input type="checkbox" class="del_all" style="margin-left: 18px !important;" checked  name="prole.roleButtonList['+index+'].del">删'
                }
                if (row.update == 1) {
                    update='<input type="checkbox" class="update_all" style="margin-left: 18px !important;" checked  name="prole.roleButtonList['+index+'].update">改'
                }
                if (row.query == 1) {
                    query='<input type="checkbox" class="query_all" style="margin-left: 18px !important;" checked  name="prole.roleButtonList['+index+'].query">查'
                }

                return [add,del,update,query].join('');
            }
        }]
    });





    function doSubmit()
    {
        var loadindex = layer.load(1, {
            shade: [0.5,'#fff'] //0.1透明度的白色背景
        });
        $.ajax( {
            url:'${pageContext.request.contextPath}/role/saveRoleButton.ac',// 跳转到 action
            data:$("#roleForm").serialize(),
            type:'post',
            cache:false,
            dataType:'json',
            success:function(data) {
                if(data=="success")
                {
                    parent.layer.msg('保存成功');
                    parent.layer.close(index);
                    layer.close(loadindex);
                }else
                {
                    parent.layer.msg(data);
                }
            },
            error : function() {
                parent.layer.msg('保存失败！');
            }
        });
    }


    function selectAllCheck(type) {
        if(type=='add'){
            if($("#addCtrl").is(':checked')==true){
                $(".add_all").prop('checked',true);
            }else{
                $(".add_all").prop('checked',false);
            }
        }else if(type=='del'){
            if($("#delCtrl").is(':checked')==true){
                $(".del_all").prop('checked',true);
            }else{
                $(".del_all").prop('checked',false);
            }
        }else if(type=='update'){
            if($("#updCtrl").is(':checked')==true){
                $(".update_all").prop('checked',true);
            }else{
                $(".update_all").prop('checked',false);
            }
        }else if(type=='query'){
            if($("#queCtrl").is(':checked')==true){
                $(".query_all").prop('checked',true);
            }else{
                $(".query_all").prop('checked',false)
            }
        }
    }


</script>
</body>
</html>

